package org.dormi.learn.primitive;


import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;

/**
 * 计量单位
 *
 * @author : dormi330
 * @version : 1.0
 */
public enum MeasureUnitEnum {

    // 长度
    LENGTH_METER("length", "METER", "米", "m"),
    LENGTH_CENTIMETER("length", "CENTIMETER", "厘米", "cm"),

    // 重量
    WEIGHT_KILOGRAM("weight", "KILOGRAM", "千克", "kg"),
    WEIGHT_GRAM("weight", "GRAM", "克", "g"),

    // 体积
    VOLUME_CUBIC_METER("volume", "CUBIC_METER", "立方米", "m^3"),
    VOLUME_CUBIC_CENTI_METER("volume", "CUBIC_CENTI_METER", "立方米", "cm^3"),

    // 时间
    TIME_YEAR("time", "YEAR", "年", "year"),
    TIME_MONTH("time", "MONTH", "月", "mon"),
    TIME_DAY("time", "DAY", "日", "day"),
    TIME_HOUR("time", "HOUR", "日", "hr"),
    TIME_MINUTE("time", "MINUTE", "分钟", "min"),

    // sku单位
    SKU_PCS("sku", "PCS", "批次", "pcs"),
    SKU_SINGLE("sku", "SINGLE", "单个", "single"),
    SKU_BOX("sku", "BOX", "箱", "box"),
    ;

    /** 类型: 如 重量, 体积, 尺寸 */
    private final String type;

    /** 编码: 如 m3, cm^3 */
    private final String code;

    /** 计量单位, 如 千克, 立方米, 厘米, 仅做展示用 */
    private final String name;

    /** 单位符号, 如 m³ , 仅做展示用 */
    private final String note;

    /* === constructor === */
    /* === constructor === */
    /* === constructor === */

    MeasureUnitEnum(String type, String code, String name, String note) {
        this.type = type;
        this.code = code;
        this.name = name;
        this.note = note;
    }

    @JsonCreator
    public static MeasureUnitEnum findValue(@JsonProperty("code") String code) {
        if (null == code) return null;

        return Arrays.stream(MeasureUnitEnum.values())
                .filter(pt -> pt.code.equals(code))
                .findFirst()
                .orElse(null);
    }

    /* === set/get === */
    /* === set/get === */
    /* === set/get === */

    public String getType() {
        return type;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getNote() {
        return note;
    }

}
